package com.example.aopdemo.demos.web;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
@Slf4j
@Aspect
//@Component
public class AspectDemo {
    @Pointcut("execution(* com.example.aopdemo.demos.web.controller..*.*(..))")
    public void pt(){

    }
    @Before("pt()")
    public  void  doBefore(){
        log.info("执行AspectDemo before");
    }
    @After("pt()")
    public  void doAfter(){
        log.info("执行AspectDemo after");
    }
    @AfterReturning("pt()")
    public  void doAfterReturning(){
        log.info("执行AspectDemo afterReturning");
    }
    @AfterThrowing("execution(* com.example.aopdemo.demos.web.controller..*.*(..))")
    public  void doAfterThrowing(){
        log.info("执行AspectDemo afterThrowing...");
    }
    @Around("execution(* com.example.aopdemo.demos.web.controller..*.*(..))")
    //Around表示的是方法前后，是必须要返回结果的
    public  Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("执行AspectDemo Around前");
        Object result=joinPoint.proceed();
        log.info("执行AspectDemo doAround 后");
        return result;
    }



}
